**********************************************************************************************
* Main run file to produce all results for Tables 1 to 7 and Appendix Figures A.1 to A.9
* 
* To replicate Table 7, intermediate steps are necessary through the causal forest analysis. For this, please refer to the 'Causal Forest' folder where the R scripts are located to replicate the causal forest analysis.
* To replicate Figure 2, please refer to the 'Causal Forest' folder where the R scripts are located to replicate the causal forest analysis.
* 
* Ajzenman, Elacqua, Jaimovich and Pérez-Núñez (2024)."Humans versus Chatbots: Scaling-up behavioral interventions to reduce teacher shortages"  	  		
*
**********************************************************************************************

clear all

* Set the project directory
global projectdir "\Replication package"

*Paths for different types of files/data
global dofilepath = "$projectdir\DoFiles"
global datapath = "$projectdir\MainData"
global output = "$projectdir\Output"
global cfpath = "$projectdir\CausalForest"

*------------------------------------------------------------------
* Data cleaning
*------------------------------------------------------------------

use "${datapath}/MainData.dta" ,clear

*generate a new ID. The original ID was removed for confidentiality.
gen mrun = _n 

*drop untreated cases from the database
drop if contacto_fallido==1
drop if inubicable_corr==1 

*replace missing values
replace  prom_cm_actual=. if  prom_cm_actual==0
replace bajo_linea_pobreza=. if linea_pobreza_na==1

*-------------------------------------------------------------------
* Main Tables 
*-------------------------------------------------------------------

* Table 1
do "${dofilepath}/Table1.do"

* Table 2
do "${dofilepath}/Table2.do"

* Table 3
do "${dofilepath}/Table3.do"

* Table 4
do "${dofilepath}/Table4.do"

* Table 5
do "${dofilepath}/Table5.do"

* Table 6
do "${dofilepath}/Table6.do"

* Table 7 
*To replicate Table 7, intermediate steps are necessary through the causal forest analysis. For this, please refer to the 'Causal Forest' folder where the R scripts are located to replicate the causal forest analysis. Intermediate results used for the table construction are stored there and are necessary as input for the code shown below.
do "${dofilepath}/Table7.do"

*-------------------------------------------------------------------
* Appendix Tables 
*-------------------------------------------------------------------

* Return to the original data after causal forest analysis. Start with data cleaning.
use "${datapath}/MainData.dta" ,clear

*generate a new ID. The original ID was removed for confidentiality.
gen mrun = _n 

*drop untreated cases from the database
drop if contacto_fallido==1
drop if inubicable_corr==1 

*replace missing values
replace  prom_cm_actual=. if  prom_cm_actual==0
replace bajo_linea_pobreza=. if linea_pobreza_na==1

* Table A1
do "${dofilepath}/TableA1.do"

* Table A2
do "${dofilepath}/TableA2.do"

* Table A3
do "${dofilepath}/TableA3.do"

* Table A4
do "${dofilepath}/TableA4.do"

* Table A5
do "${dofilepath}/TableA5.do"

* Table A6
do "${dofilepath}/TableA6.do"

* Table A7
do "${dofilepath}/TableA7.do"

* Table A8
do "${dofilepath}/TableA8.do"

* Table A9
do "${dofilepath}/TableA9.do"
